package org.bemuv;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.view.Menu;
import android.view.Window;

import org.bemuv.R;
import com.parse.Parse; //Libreria del backend
import com.parse.ParseUser;

public class SplashScreenActivity extends Activity {

	// Set the duration of the splash screen
	private static final long SPLASH_SCREEN_DELAY = 10000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Set portrait orientation
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		// Hide title bar
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_splash_screen);
		TimerTask task = new TimerTask() {
			@Override
			public void run() {
				// Start the next activity
				Intent i;
				ParseUser currentUser = ParseUser.getCurrentUser();
				if (currentUser != null) {
					// do stuff with the user
					i = new Intent().setClass(SplashScreenActivity.this,
							HomeActivity.class);
				} else {
					// show the signup or login screen
					i = new Intent().setClass(SplashScreenActivity.this,
							SignInActivity.class);
				}
				startActivity(i);

				// Close the activity so the user won't able to go back this
				// activity pressing Back button
				finish();
			}
		};
		// Simulate a long loading process on application startup.
		Timer timer = new Timer();
		timer.schedule(task, SPLASH_SCREEN_DELAY);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_splash_screen, menu);
		return true;
	}

}
